package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JComboBox;
import javax.swing.JLabel;


public class CommandLineListener implements ActionListener{

	public CommandLineListener(JLabel vn) {
		volumeName = vn;		
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void actionPerformed(ActionEvent arg0) {		
	
			commandLine = (JComboBox)arg0.getSource();
			commandLine.setPopupVisible(false);
			String path = volumeName.getText();
	        path += (String)commandLine.getSelectedItem();			
			
			if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ) {				
				try {						
					Runtime.getRuntime().exec(new String[] {"explorer.exe", path});
				} catch (IOException e) {						
					e.printStackTrace();
				}	
			}	
			
			if (commandLine.getItemCount() < 5 ) {
				commandLine.addItem(path);					
			} else {
				commandLine.addItem(path);
				commandLine.removeItemAt(0);
			}
	}			
	
	private JComboBox<String>  commandLine;
	private JLabel volumeName;
	
	
}



